package com.jungle.bfi.controller;

import com.jungle.base.dao.SpecBuilder;
import com.jungle.base.domain.bo.BaseUserBo;
import com.jungle.base.domain.vo.JsonResult;
import com.jungle.bfi.domain.bo.VoucherTypeBo;
import com.jungle.bfi.entity.VoucherTypePo;
import com.jungle.bfi.service.voucher.VoucherTypeService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * [voucher]凭证类型(凭证字)
 * @author jungle
 * @since 2025-02-20 08:54:27
 */
@Slf4j
@RestController
@RequestMapping("voucherType")
public class VoucherTypeController {
    @Resource
    private VoucherTypeService voucherTypeService;
    @PostMapping("store")
    public JsonResult<VoucherTypePo> store(@RequestBody VoucherTypeBo qo) {
        VoucherTypePo po = voucherTypeService.saveOrUpdate(qo, new BaseUserBo());
        return JsonResult.success(po);
    }

    @GetMapping("delete")
    public JsonResult<Void> delete(@RequestParam String id) {
        voucherTypeService.deleteById(id);
        return JsonResult.success();
    }

    @PostMapping("list")
    public JsonResult<List<VoucherTypePo>> list(@RequestBody VoucherTypeBo bo) {
        List<VoucherTypePo> list = voucherTypeService.findAll(new SpecBuilder<VoucherTypePo>(bo).toSpec());
        return JsonResult.success(list);
    }
}
